package com.eastmelon.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author eastmelon
 * @date 2016年8月10日下午6:24:37
 * @version 1.0
 * @description 通过缓冲区来复制文件
 */
public class CopyByBuf {
	public static void main(String[] args) {
		BufferedReader bufr = null;
		BufferedWriter bufw = null;
		try {
			bufr = new BufferedReader(new FileReader("D:\\test.txt"));
			bufw = new BufferedWriter(new FileWriter("D:\\test3.txt"));
			String str=null;
			while((str=bufr.readLine())!=null){
				bufw.write(str);
				bufw.newLine();//返回的一行不包含终止符
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (bufr != null)
					bufw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				if (bufw != null)
					bufr.close();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
	}

}
